Once I had my code I needed a way of testing it. After some thought I wrote a program which read a value from the EEPROM and displayed it. It then added one to the value and stored it again. To do this I needed something which can display numbers and so I raided the stopwatch program for code which can drive the 7 segment displays. If I turn the PICmicro off and then back on again I should see a number which increases by 1 each time.
You can find the full source for this program in Exercise 7.1. Run it and note the number. Then turn off the power and run it again. Note that the number gets bigger each time you run it. The very first time you run it you will get whatever value is in the EEPROM at that location. For some reason my PIC microcontroller gave me the value 0009, but yours may be different. Note that we now have a way that a program can record how many times it has been run. This could be useful if you were releasing a "demo" version of a device and you only wanted it to be used a number of times, for a particular length of time.
void main ( void )
{
unsigned char test ;
setup_hardware () ;
test = read_eeprom ( EEPROMLOCATION ) ;
display_value ( test ) ;
test = test + 1 ;
write_eeprom ( EEPROMLOCATION , test ) ;
while (1)
{
}
}